package com.da.javatest.test.basic;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import cn.hutool.jwt.JWT;
import com.da.javatest.job.JobHandle;
import com.da.javatest.util.HolidayUtils;
import com.google.common.collect.Lists;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @author JokerDa.
 * @date 2023/3/1 10:59
 * Description:
 */
public class JavaTest2 {
    @Test
    public void test1() {
        List<Long> ids = Arrays.stream("111,112,118".split(",")).map(Long::valueOf).collect(
            Collectors.toList());
        System.out.println(ids);

        System.out.println(DateUtil.format(DateUtil.yesterday(), DatePattern.NORM_DATE_PATTERN));
    }

    @Test
    public void test2() {
        try {
            //抽取url网页中的内容，content内容太短的不入库

            File file = new File("C:\\Users\\Administrator\\Desktop\\OnlineDAG品类价格清单.xlsx");
            FileInputStream fs = new FileInputStream(file);

            XSSFWorkbook wb = new XSSFWorkbook(fs);
            XSSFSheet sheet = wb.getSheetAt(0);//获取到工作表，因为一个excel可能有多个工作表
            FileOutputStream out = new FileOutputStream(file);  //向d://test.xls中写数据
            //在现有行号后追加数据
            XSSFRow row = sheet.createRow((2 + 1));
            System.out.println(sheet.getLastRowNum());
            row.createCell(0).setCellValue("CN17"); //设置第一个（从0开始）单元格的数据
            row.createCell(1).setCellValue("CN17"); //设置第二个（从0开始）单元格的数据
            row.createCell(2).setCellValue("CN17");
            row.createCell(6).setCellValue("CN17");
            out.flush();
            wb.write(out);
            out.close();
            fs.close();
        } catch (Throwable e) {
            System.out.println(e.getMessage());
        }
    }

    @Test
    public void test3() throws InterruptedException {
        File file = HttpUtil.downloadFileFromUrl(
            "https://abi-vp-offline.oss-cn-shanghai.aliyuncs.com/budweiser/template/OnlineDAG.xlsx",
            "OnlineDAG品类价格清单.xlsx");

        System.out.println(file.getAbsolutePath());
        try (
            // 向file中写数据
            FileInputStream fs = new FileInputStream(file);
            XSSFWorkbook wb = new XSSFWorkbook(fs);
            FileOutputStream out = new FileOutputStream(file);
        ) {
            //抽取url网页中的内容，content内容太短的不入库
            XSSFSheet sheet = wb.getSheetAt(0);//获取到工作表，因为一个excel可能有多个工作表
            //在现有行号后追加数据
            XSSFRow row = sheet.createRow((2 + 1));
            row.createCell(0).setCellValue("CN17"); //设置第一个（从0开始）单元格的数据
            row.createCell(1).setCellValue("CN17"); //设置第二个（从0开始）单元格的数据
            row.createCell(2).setCellValue("CN17");
            row.createCell(6).setCellValue("CN17");
            out.flush();
            wb.write(out);
        } catch (Throwable e) {
            System.out.println(e.getMessage());
        }
        Thread.sleep(3000);
        file.deleteOnExit();
    }

    @Test
    public void test4() {
        List<Integer> list = Arrays.asList(1, null, 2, null, 3);
        System.out.println(list.stream().filter(Objects::nonNull).collect(Collectors.toList()));
        System.out.println(list.get(list.size() - 1));

        //List<Integer> list3 = Arrays.asList();
        //System.out.println(list3.get(list3.size() - 1));

        List<String> list2 = Arrays.asList(null, null);
        System.out.println(list2.stream().filter(Objects::nonNull).collect(Collectors.toList()));
        String collect = list2.stream().filter(Objects::nonNull).collect(Collectors.joining(","));
        System.out.println(StrUtil.isBlank(collect));
        System.out.println(collect);

        String a = "1100010";
        String b = a.substring(0, a.length() - 1) + "1";
        System.out.println(b);

        Map<Boolean, List<String>> listMap = list2.stream().filter(Objects::nonNull).collect(
            Collectors.groupingBy(x -> x.trim().equals("a")));
        System.out.println(listMap.get("aa"));
        System.out.println(listMap);

        System.out.println("M245".toLowerCase().substring(0, 1));
    }

    @Test
    public void test5() {
        //List<String> list = Collections.singletonList("hhh");
        //list.addAll(Arrays.asList("1", "2"));

        System.out.println("Reverse Japanese".split(" ")[1]);

        System.out.println(Convert.toDouble(new BigDecimal(22.22)));
        System.out.println(Convert.toDouble(new BigDecimal(22.21)));
        System.out.println(Convert.toDouble(new BigDecimal(22.23)));
        System.out.println(Convert.toDouble(new BigDecimal(22.24)));
        System.out.println(Convert.toDouble(new BigDecimal(22.00)));

        List<Integer> l1 = Lists.newArrayList(1, 2, 3, 4, 5);
        List<Integer> l2 = Lists.newArrayList(2, 4, 5, 8);
        List<Integer> l3 = Lists.newArrayList(1, 2, 3, 4, 5);
        l1.removeAll(l2);
        System.out.println(l1);
        System.out.println(CollectionUtil.isEmpty(l1));
        l1.removeAll(l3);
        System.out.println(l1);
        System.out.println(CollectionUtil.isEmpty(l1));

        String str = "0001110";
        System.out.println(str.substring(3, 6));

        System.out.println(DateUtil.year(new Date()));

        BigDecimal decimal = new BigDecimal(100);
        System.out.println(decimal.multiply(BigDecimal.ONE));
        System.out.println(decimal.multiply(BigDecimal.ZERO));
    }

    @Test
    public void test6() {
        List<Student> students = Collections.emptyList();
        int sum = students.stream().mapToInt(Student::getId).sum();
        System.out.println(sum);

        //假设你的入参,你的组织最多两层
        List<List<String>> orgCodeReq = Arrays.asList(Arrays.asList("0000100004", "0000100022"),
            Arrays.asList("0000106471"));
        //声明一级组织CODE
        List<String> buCode = new ArrayList<>();
        //声明二级组织CODE
        List<String> regionCode = new ArrayList<>();
        String level = "BU";
        for (List<String> orgCodeList : orgCodeReq) {
            //转map 防止数组越界
            Map<Integer, String> orgCodeListToMap = IntStream.range(0, orgCodeList.size()).boxed().collect(
                Collectors.toMap(Function.identity(), orgCodeList::get));
            buCode.add(Objects.nonNull(orgCodeListToMap.get(0)) ? orgCodeListToMap.get(0) : null);
            regionCode.add(Objects.nonNull(orgCodeListToMap.get(1)) ? orgCodeListToMap.get(1) : null);
        }
        //这个判断放在数据库中
        System.out.println(JSONUtil.toJsonStr(buCode));
        System.out.println(JSONUtil.toJsonStr(regionCode));

    }

    @Test
    public void test8() {
        System.out.println(DateUtil.yesterday());
        DateTime time = DateUtil.parse("202301", "yyyyMM");
        System.out.println(time);
        Calendar calendar = time.toCalendar();
        calendar.add(Calendar.MONTH, -1);
        System.out.println(DateUtil.formatDate(calendar.getTime()));
        calendar = time.toCalendar();
        calendar.add(Calendar.DATE, -1);
        System.out.println(DateUtil.formatDate(calendar.getTime()));
        System.out.println("============================");
        System.out.println(DateUtil.formatDate(time.toJdkDate()));
        calendar = time.toCalendar();
        calendar.add(Calendar.MONTH, 1);
        calendar.add(Calendar.DATE, -1);
        System.out.println(DateUtil.formatDate(calendar.getTime()));

    }

    @Test
    public void test9() {
        DateTime time = DateUtil.parse("2021-11", DatePattern.NORM_MONTH_PATTERN);
        DateTime time2 = DateUtil.parse("202203", DatePattern.SIMPLE_MONTH_PATTERN);
        System.out.println(DateUtil.betweenMonth(time, time2, true));
        //Period period = Period.between(time, time2);
        String str = "https://budlibrary.ab-inbev.cn:8001/document/preDownloadV2";
        String str2 = "https://budlibrarytest.ab-inbev.cn:8001/document/preDownloadV2";
        System.out.println(str.replace(":8001", ""));
        System.out.println(str2.contains("test"));

        System.out.println(DateUtil.format(new Date(), "dd"));

        List<List<String>> codes = Arrays.asList(Arrays.asList("aa", "bb"), Arrays.asList("bb", "cc"),
            Arrays.asList("dd", "ff"));
        System.out.println(codes.stream().flatMap(Collection::stream).distinct().collect(Collectors.toList()));
    }

    @Test
    public void test10() throws ParseException {
        System.out.println(handlerShow(new BigDecimal("100.00")));
        System.out.println(handlerShow(new BigDecimal("80.60")));

        String kay = "100000000062202311loyalty0000106471";
        System.out.println(kay.substring(0, 12));
        System.out.println(kay.substring(12, 18));

        Date now = new Date();
        System.out.println(getMonthSpace(DateUtil.parseDate("2023-01-01").toJdkDate(), now));
        System.out.println(getMonthSpace(DateUtil.parseDate("2022-12-01").toJdkDate(), now));
        System.out.println(getMonthSpace(DateUtil.parseDate("2024-01-01").toJdkDate(), now));
        System.out.println("-------------");
        System.out.println(getMonthSpace("202301", now));
        System.out.println(getMonthSpace("202310", now));
        System.out.println(getMonthSpace("202401", now));

        System.out.println(new BigDecimal("2.46").longValue());
        System.out.println(new BigDecimal("2.66").longValue());
        System.out.println(Convert.toDouble(new BigDecimal("2.46")));
    }

    @Test
    public void test11() {
        List<Student> list = new ArrayList<>();
        Student student = new Student(1, "aa");
        list.add(student);
        student = new Student(2, "bb");
        list.add(student);
        student = new Student(3, "cc");
        list.add(student);
        System.out.println(list);

        BigDecimal bigDecimal = new BigDecimal(0);
        System.out.println(bigDecimal.equals(BigDecimal.ZERO));
        System.out.println(BigDecimal.ZERO.equals(null));
    }

    private String handlerShow(BigDecimal value) {
        if (Objects.nonNull(value)) {
            return value.stripTrailingZeros().toPlainString() + "%";
        }
        return "";
    }

    public static int getMonthSpace(Date date, Date now) throws ParseException {
        String format = "yyyyMM";
        SimpleDateFormat sdf = new SimpleDateFormat(format);

        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();

        c1.setTime(sdf.parse(DateUtil.format(now, format)));
        c2.setTime(sdf.parse(DateUtil.format(date, format)));

        int result = c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH);
        int month = (c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR)) * 12;

        return Math.abs(month + result);
    }

    public static int getMonthSpace(String dateStr, Date date) throws ParseException {
        String format = "yyyyMM";
        SimpleDateFormat sdf = new SimpleDateFormat(format);

        Calendar c1 = Calendar.getInstance();
        Calendar c2 = Calendar.getInstance();

        c1.setTime(sdf.parse(dateStr));
        c2.setTime(sdf.parse(DateUtil.format(date, format)));

        int result = c1.get(Calendar.MONTH) - c2.get(Calendar.MONTH);
        int month = (c1.get(Calendar.YEAR) - c2.get(Calendar.YEAR)) * 12;

        return Math.abs(month + result);
    }

    @Test
    public void test12() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> m1 = new HashMap<>();
        m1.put("aa", "");
        m1.put("bb", "bb");
        m1.put("cc", null);
        Map<String, Object> m2 = new HashMap<>();
        m2.put("aa", "");
        m2.put("bb", "bb");
        m2.put("cc", null);
        list.add(m1);
        list.add(m2);
        handleResData(list);
        System.out.println(list);
    }

    private void handleResData(List<Map<String, Object>> list) {
        if (CollectionUtil.isNotEmpty(list)) {
            list.forEach(x -> {
                for (Entry<String, Object> entry : x.entrySet()) {
                    if (Objects.isNull(entry.getValue()) || StrUtil.isBlank(entry.getValue().toString().trim())) {
                        entry.setValue("-");
                    }
                }
            });
        }
    }

    @Test
    public void test13() {
        String str = "{\"hq_bu\":\"中区|BU_C\",\"business_type\":\"KOL\",\"kol\":\"Non-KOL\",\"tam_code\":\"01123\","
            + "\"brand\":\"威卡\",\"zbb_subpackage\":\"Fees\",\"fourth_level\":\"four\",\"factory\":\"CN10\","
            + "\"material_code\":\"0123\",\"gl_account\":\"0001001000\",\"activity_area\":\"HQ\","
            + "\"activity_type\":\"音乐节\",\"capex_tag\":\"capex\"}";
        System.out.println(DateUtil.currentSeconds());
        System.out.println(DigestUtil.md5Hex(str));
    }

    @Test
    public void test14() {
        Student student = new Student(1, "");
        System.out.println(JSONUtil.toJsonStr(JSONUtil.parseObj(student, false)));

        student = new Student();
        student.setName("123");
        System.out.println(JSONUtil.toJsonStr(JSONUtil.parseObj(student, false)));

        student = new Student();
        student.setId(1);
        System.out.println(JSONUtil.toJsonStr(JSONUtil.parseObj(student, false)));

        student = new Student(1, null);
        System.out.println(JSON.toJSONString(student, SerializerFeature.WriteNullStringAsEmpty));

        System.out.println(BigDecimal.ZERO.add(new BigDecimal("1.1")));
    }

    @Test
    public void test15() {
        System.out.println(convertDate("11/1/2023 12:00:00 AM"));

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtil.lastWeek().toJdkDate());
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Date zeroTime = calendar.getTime();
        System.out.println(zeroTime);

        String startTime = DateUtil.format(DateUtil.lastWeek().toJdkDate(), DatePattern.NORM_DATE_PATTERN);
        startTime += " 00:00:00";
        System.out.println(startTime);

        Map<String, Object> queryParams = new HashMap<>();
        queryParams.put("factoryCn", "百威武汉");
        queryParams.put("planStartTime", startTime);
        String body = HttpRequest.get("https://tsmtest.ab-inbev.cn/openapi/pkg/pkgPlan/list")
            .header("token",
                "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9" +
                    ".eyJleHAiOjE3MTk2NDE1OTQsImluZm8iOiJ7XCJ1c2VyTmFtZVwiOlwi6Zu35piOXCIsXCJpcFwiOm51bGwsXCJzZWNvbmRcIjo2MCxcImRlc1wiOlwiV0Va5Lit5aSu5o6n5Yi25a6k5aSn5bGP5bGV56S6XCIsXCJhcHBsaWNhbnRcIjpcIkNDUlwifSJ9.ZWmtj74N-wOkmu4es0k1p81cBwDtFh-PeFllvM4TEw8")//头信息，多个头信息多次调用此方法即可
            .form(queryParams)//表单内容
            .timeout(20000)//超时，毫秒
            .execute().body();
        System.out.println(body);
    }

    public static Date convertDate(String dateStr) {
        String strDateFormat = "MM/dd/yyyy hh:mm:ss aa";
        try {
            Date date = new SimpleDateFormat(strDateFormat, Locale.ENGLISH).parse(dateStr);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Test
    public void test18() {
        BigDecimal b1 = new BigDecimal("2.3");
        BigDecimal b2 = new BigDecimal("2.3");
        BigDecimal b3 = new BigDecimal("2.2");
        System.out.println(b1.compareTo(b2));
        System.out.println(b3.compareTo(b2));

        Date d1 = new Date();
        Date d2 = new Date();
        Date d3 = new Date(10086L);
        System.out.println(d1.compareTo(d2));
        System.out.println(d3.compareTo(d2));

        Date date = DateUtil.parse("2024-01-01", DatePattern.NORM_DATE_PATTERN).toJdkDate();
        Date date2 = DateUtil.parse("2024-12-01", DatePattern.NORM_DATE_PATTERN).toJdkDate();

        int year = DateUtil.year(d1);
        int month = DateUtil.month(d1);
        System.out.println(year);
        System.out.println(month);

        year = DateUtil.year(date);
        month = DateUtil.month(date);
        System.out.println(year);
        System.out.println(month);

        year = DateUtil.year(date2);
        month = DateUtil.month(date2);
        System.out.println(year);
        System.out.println(month);
    }

    @Test
    public void test19() {
        String str = "[\"2024-01-01\",\"2024-01-02\"]";
        JSONArray array = JSONUtil.parseArray(str);
        List<String> list = array.toList(String.class);
        System.out.println(list);
        System.out.println(JSONUtil.toJsonStr(list));
    }

    @Test
    public void test20() {
        System.out.println(HolidayUtils.getHoliday(2024, 6));

        LocalDateTime now = LocalDateTime.now();
        long weeksToAdd = 6;

        LocalDateTime futureDateTime = now.plusWeeks(weeksToAdd);
        Date date = Date.from(futureDateTime.atZone(ZoneId.systemDefault()).toInstant());
        Date jdkDate = DateUtil.beginOfWeek(date).toJdkDate();

        System.out.println("当前时间：" + now);
        System.out.println("6周后的时间：" + futureDateTime);
        System.out.println("6周后的时间：" + jdkDate);
    }

    @Test
    public void test21() {
        List<Date> dates = Arrays.asList(getAfterWeeks(5), getAfterWeeks(3), getAfterWeeks(2), getAfterWeeks(8),
            getAfterWeeks(4));
        Date date = dates.stream().max(Comparator.comparing(Date::getTime)).get();
        System.out.println(date);

        BigDecimal b = new BigDecimal("100");
        BigDecimal bigDecimal = new BigDecimal("122.356");
        System.out.println(bigDecimal.compareTo(b));
        System.out.println(bigDecimal.scale());

        Date toJdkDate = DateUtil.parse("2024-05-01D", DatePattern.NORM_DATE_PATTERN).toJdkDate();
        System.out.println(toJdkDate);
        //toJdkDate = DateUtil.parse("AAA", DatePattern.NORM_DATE_PATTERN).toJdkDate();
        System.out.println(UUID.fastUUID().toString(true));
        System.out.println("v" + DateUtil.format(new Date(), "yyyy.MM.dd"));

        System.out.println("20240801".substring(0, 6));

        Date now = DateUtil.beginOfMonth(new Date()).toJdkDate();
        String number = "20240701";
        Date version = DateUtil.parse(number, "yyyyMMdd").toJdkDate();
        System.out.println(version.before(now));
    }

    private Date getAfterWeeks(int weeksToAdd) {
        LocalDateTime now = LocalDateTime.now();

        LocalDateTime futureDateTime = now.plusWeeks(weeksToAdd);
        Date date = Date.from(futureDateTime.atZone(ZoneId.systemDefault()).toInstant());
        return DateUtil.beginOfWeek(date).toJdkDate();
    }

    @Test
    public void test22() {
        Date date = addMinute(new Date(), 120);
        System.out.println(DateUtil.formatDateTime(date));
        System.out.println(getAfterMonth(-1));

        DecimalFormat df = new DecimalFormat("00");
        System.out.println(df.format(5));
        System.out.println(df.format(12));
        List<Integer> list = Arrays.asList(1, 2, 3);
        List<Integer> list1 = Arrays.asList(4, 2, 3);
        Collection<Integer> d1 = CollectionUtil.disjunction(list, list1);
        Collection<Integer> d2 = CollectionUtil.disjunction(list1, list);
        List<Integer> vendorCodes = new ArrayList<>(CollectionUtil.unionDistinct(d1, d2));
        System.out.println(vendorCodes);

        String infoTemplate = "【{}】为新物料批次，是否自动生成质检计划？";
        System.out.println(StrUtil.format(infoTemplate, "aaa"));

    }

    private Date addMinute(Date planStartTime, int minute) {
        if (planStartTime == null) {
            return null;
        }
        LocalDateTime localDateTime = DateUtil.toLocalDateTime(planStartTime);
        LocalDateTime dateTime = localDateTime.plusMinutes(minute);
        return Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
    }

    private String getAfterMonth(int weeksToAdd) {
        LocalDateTime now = LocalDateTime.now();

        LocalDateTime futureDateTime = now.plusMonths(weeksToAdd);
        Date date = Date.from(futureDateTime.atZone(ZoneId.systemDefault()).toInstant());
        return DateUtil.format(DateUtil.beginOfMonth(date).toJdkDate(), "yyyy-MM-dd");
    }

    @Test
    public void test23() {
        MD5 md5 = MD5.create();
        System.out.println(md5.digestHex("123456"));
        System.out.println(md5.digestHex("123321"));

        String text = md5.digestHex("123456");
        System.out.println(
            text.substring(0, 3) + text.substring(8, 11) + text.substring(16, 19) + text.substring(24, 27));

        // 获取当前月份最后一天
        Date endOfMonth = DateUtil.endOfMonth(new Date());
        // 获取当月天数
        int daysOfMonth = DateUtil.dayOfMonth(endOfMonth);
        System.out.println("当月天数: " + daysOfMonth);

        String act = "2024-08-01".replaceAll("-", "") + "PP-R0001" + StringUtils.leftPad("ACT", 6, "0") + "C195" + "D";
        System.out.println(act);

        System.out.println(DateUtil.parse("9999-12-31", "yyyy-MM-dd"));

        System.out.println(YearMonth.parse("2024-11-28", DateTimeFormatter.ISO_LOCAL_DATE).lengthOfMonth());
        System.out.println("2024-11-28".substring(0, 8));
    }

    @Test
    public void test24() {
        // 假设这是你的JWT
        String jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5GSUp5NUpER3c1aFl2QXNuSHBkQk9iR0g3NCJ9" +
            ".eyJhdWQiOiJmZDQ4YWE1NS0xNzAyLTRhMjUtOTM0Yi1jYWYyMzg1ZTA3OWQiLCJpc3MiOiJodHRwczovL2xvZ2luLnBhcnRuZXIubWljcm9zb2Z0b25saW5lLmNuL2M5OWIyM2I2LTRmYTgtNGVlZS1hN2NjLTJmNDIwMTA2ZTczMC92Mi4wIiwiaWF0IjoxNzMxMzgxMjUzLCJuYmYiOjE3MzEzODEyNTMsImV4cCI6MTczMTM4NTE1MywibmFtZSI6InpvdSwgemhpeW9uZyIsIm5vbmNlIjoiMDE5MzFlNjEtOThjZi03MGY4LTgzMzMtNWY2MGM3MGJjZDRlIiwib2lkIjoiODRjZDJiZjYtYTE3MC00ZTA4LWEzYzMtNWJhZWFlMDE4ZmJkIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidl96aGl5b25nem91MUBidWR3ZWlzZXJhcGFjLmNvbSIsInJoIjoiMS5EQUlBdGlPYnlhaFA3azZuekM5Q0FRYm5NRldxU1AwQ0Z5VktrMHZLOGpoZUI1MENBSk1DQUEuIiwic3ViIjoiMXQ4ZDlUbTZPU3VzNV9kZFdnTldSMk9ZalRBOEZvOHBmVE0weW5UZHFoRSIsInRpZCI6ImM5OWIyM2I2LTRmYTgtNGVlZS1hN2NjLTJmNDIwMTA2ZTczMCIsInV0aSI6InZXSzVSRDltMkUtMzdCQkxPcEtDQVEiLCJ2ZXIiOiIyLjAifQ.l14ug_tqxpCxRNNbrJaYpFpzr-uAtE3cmrkyDeBrT2RJDa6ymfXrg6gC_ISiQ-7zAnoDY8SsP73b9SDFwlsw8k1jUAilskfeiIKgcwBlx06OsE93_NSodYyHwlx3hPyYMhGwcds0ZzRBqo7vUccKt358Au7iBaXJe6i4x_LGDeQDyLlfKQpKdJGyvKxbA2Dc6FPUSw9KHYPVRka_gdIZPmbtDW2G_uxCawfD3_cgvR0PvEdsWJFOur-0WQiXJdly_Mw_xp2u-kx8NM3Egg-qBFqQTCWdb0_1zfQYYb7HHW-F5A3Mgl9KQTda09oQT3jaaM_kkq3dlbg0Y7Qxe0DJcQ";
        // 解析JWT
        JWT jwtObject = JWT.of(jwt);

        // 获取JWT内容
        String payload = jwtObject.getPayload().toString();
        System.out.println("Payload: " + payload);

        String email = jwtObject.getPayload("preferred_username").toString();
        System.out.println("email: " + email);

        String aa = jwtObject.getPayload("aa").toString();
        System.out.println("aa: " + aa);

        //// 验证JWT是否有效
        //boolean isVerify = jwtObject.verify("secret".getBytes());
        //System.out.println("Is JWT verified? " + isVerify);
        //
        //// 解析JWT的头部
        //String header = jwtObject.getHeader();
        //System.out.println("Header: " + header);
        //
        //// 解析JWT中的特定字段
        //String issuer = jwtObject.get("iss", String.class);
        //System.out.println("Issuer: " + issuer);
    }

    @Test
    public void test25() {
        String name = "aaa.xlsx";
        String fileName = FilenameUtils.getBaseName(name);
        String extension = FilenameUtils.getExtension(name);
        System.out.println(fileName);
        System.out.println(extension);
    }

    @Test
    public void test26() {
        //动态的添加定时任务每5秒执行一次
        String schedule = CronUtil.schedule("*/5 * * * * *", new Task() {
            @Override
            public void execute() {
                Console.log("动态定时任务，每5秒执行一次");
            }
        });
        System.out.println(schedule);
        //支持秒级
        CronUtil.setMatchSecond(true);
        //开启定时任务
        CronUtil.start(true);
        while (true) {

        }
    }

    @Test
    public void test27() throws Exception {
        SchedulerFactory schedulerFactory = new StdSchedulerFactory();
        Scheduler scheduler = schedulerFactory.getScheduler();

        // 定义任务细节
        JobDetail jobDetail = JobBuilder.newJob(JobHandle.class)
            .withIdentity("myJob", "group1")
            .usingJobData("aa", "aa")
            .build();

        Trigger trigger = TriggerBuilder.newTrigger()
            .withIdentity("myJob", "group1")
            .withSchedule(CronScheduleBuilder.cronSchedule("0/3 * * * * ?")) // 每5分钟执行一次
            .build();

        // 将任务细节和触发器注册到调度器
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();

        // 定义任务细节
        JobDetail jobDetail2 = JobBuilder.newJob(JobHandle.class)
            .withIdentity("myJob1", "group1")
            .usingJobData("aa", "bb")
            .build();

        Trigger trigger2 = TriggerBuilder.newTrigger()
            .withIdentity("myJob1", "group1")
            .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")) // 每5分钟执行一次
            .build();

        // 将任务细节和触发器注册到调度器
        scheduler.scheduleJob(jobDetail2, trigger2);

        // 启动调度器
        //scheduler.deleteJob(JobKey.jobKey("myJob1", "group1"));
        while (true) {

        }
    }

    @Test
    public void test28() {
        DateTime dateTime = DateUtil.parse("20241204", "yyyyMMdd");
        Date now = DateUtil.parse(DateUtil.format(new Date(), "yyyy-MM-dd"), "yyyy-MM-dd").toJdkDate();
        Date date = dateTime.toJdkDate();
        if (date.compareTo(now) >= 0) {
            System.out.println("aaa");
        }

        String dateStr = "2024-12-01";
        Date jdkDate = DateUtil.parse(dateStr, "yyyy-MM-dd").toJdkDate();
        DateTime end = DateUtil.endOfWeek(jdkDate);
        DateTime begin = DateUtil.beginOfWeek(jdkDate);
        System.out.println(DateUtil.month(end) - DateUtil.month(begin) != 0);

        System.out.println(DateUtil.beginOfMonth(new Date()).toLocalDateTime().plusMonths(1L).toLocalDate());
    }

    @Test
    public void test7() {
        List<Integer> list = Lists.newArrayList(837592, 301299, 301289, 300380, 300465, 300773, 3315);
        int count = 0;
        change(list, count);

        System.out.println();
        list = Lists.newArrayList(301509, 3011, 2377, 301519, 301045, 300149, 3281);
        count = 0;
        change(list, count);
    }

    private void change(List<Integer> list, int count) {
        List<Integer> sort = new ArrayList<>();
        int i;
        for (Integer integer : list) {
            count++;
            if (count < 7) {
                i = integer % 33;
                if (i == 0) {
                    i = 33;
                }
            } else {
                i = integer % 16;
                if (i == 0) {
                    i = 16;
                }
            }
            sort.add(i);
            System.out.print(i + " ");
        }
    }
}
